﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using pay.Entity;
using pay.BLL;
using System.Collections;
using System.Text;

public partial class shopping11 : System.Web.UI.Page
{
    List<ShopCard> lst = null;
    public string str_products = "没有任何商品";
    int productid = 20;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
            Test();
            str_products = getList().ToString();
          
        }
    }

    ShopCard sc = null;
    public void Test()
    {
  
        if (Session["EmoneyShopCard"] == null)
        {
            try
            {
                lst = new List<ShopCard>();
                sc = new ShopCard();
                sc.Count = 1;
                sc.ProductId = productid;
                lst.Add(sc);
                Session["EmoneyShopCard"] = lst;
            }
            catch(Exception ex)
            {
                Response.Write("<script>alert('"+ex.Message+"'); this.history.back(-1);</script>");
            }
        }
        else
        {
            lst = (List<ShopCard>)Session["EmoneyShopCard"];
            bool flag = true;
            for (int i = 0; i < lst.Count; i++)
            {
                sc = lst[i];
                if (productid == sc.ProductId)
                {
                    flag = false;
                }
            }
            if (flag)
            {
                sc = new ShopCard();
                sc.Count = 1;
                sc.ProductId = productid;
                lst.Add(sc);
            }
            Session["EmoneyShopCard"] = lst;
        }
    }
    public double sum = 0;
    List<ShopCard> list = null;
    ProductBLL bll = new ProductBLL();
    public StringBuilder getList()
    {
        StringBuilder sb = new StringBuilder();
        list = (List<ShopCard>)Session["EmoneyShopCard"];
        if (list == null)
        {
            return sb;
        }
        foreach (var c in list)
        {
            Product product = bll.GetElementById(c.ProductId);
            try
            {
                c.ProductName = product.Productname;
                c.Price = product.Nowprice.Value;
                sum += c.Amount;
                sb.AppendLine("<ul class=\"product_zong\">");
                sb.AppendLine("<li class=\"product_zong1\"><a href=\"#\" class=\"b\">" + c.ProductName + "</a></li>");
                sb.AppendLine("<li class=\"product_zong2\" id=\"price\">" + c.Price + "元</li>");
                sb.AppendLine("<li class=\"product_zong2 product_zong22  \">");
                sb.AppendLine("<table width=\"230\" border=\"0\" class=\"bdxuan\">");
                sb.AppendLine("<tr>");
                sb.AppendLine("<td  class=\"bdxuan_xiao\"></td>");
                sb.AppendLine("<td  class==\"bdxuan_z\">"+c.Count+"</td>");
                sb.AppendLine("<td class=\"bdxuan_xiao\"></td>");
                sb.AppendLine("<td class=\"bdxuan_xiao\"></td>");
                sb.AppendLine("<td id=\"ck_count" + c.ProductId + "\" name=\"ck_count\"  class=\"bdxuan_zhong\"></td>");
                sb.AppendLine("</tr>");
                sb.AppendLine("</table>");
                sb.AppendLine("</li>");
                sb.AppendLine("<li class=\"product_zong3\" id=\"amount" + c.ProductId + "\">" + c.Amount + "元</li>");
                sb.AppendLine("</ul>");
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }
        return sb;
    }
}